package com.aduerr.v1shouyin.util;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class SecrectAction {

    private SecrectDB dbHelper;
    private SQLiteDatabase db;


    public SecrectAction(Context context) {
        super();
        dbHelper = new SecrectDB(context);
    }

    // 添加数据
    public Long saveData(ContentValues values) {
        db = dbHelper.getWritableDatabase();
        return db.insert("secrect", null, values);
    }

    // 查找数据
    public String queryData() {
        String deviceId = null;
        db = dbHelper.getReadableDatabase();
        Cursor cursor = db.rawQuery("select * from secrect", null);
        Log.e("CommonData", "------------" + cursor.getCount());
        while(cursor.moveToNext()) {
            // 根据列名获取索引 DeviceID text,DeviceSecret
            int index = cursor.getColumnIndex("DeviceID");
            deviceId = cursor.getString(index);
        }
        cursor.close();
        return deviceId;
    }

    // 清空数据
    public void deleteData() {
        db = dbHelper.getWritableDatabase();
        db.delete("secrect", null, null);
    }

    // 关闭数据�?
    public void closeDB() {
        if(db != null) {
            db.close();
        }
    }
}
